﻿namespace ExamV5.ZiExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSetParm : Page
    {
        protected Button butDefault;
        protected DropDownList DDLEndH;
        protected DropDownList DDLEndM;
        protected DropDownList DDLStartH;
        protected DropDownList DDLStartM;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected string strReUserCode = "";
        protected string strReUserName = "";
        protected TextBox txtEndDate;
        protected TextBox txtNum;
        protected TextBox txtStartDate;
        protected TextBox txtTime;
        protected UpdatePanel UPPart;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str = "";
            string str2 = "";
            str = base.Request.Form["txtBrowUserCode"].ToString();
            str2 = base.Request.Form["txtBrowUserName"].ToString();
            this.strReUserName = str2;
            this.strReUserCode = str;
            string str3 = this.txtStartDate.Text.Trim() + " " + this.DDLStartH.SelectedItem.Value + ":" + this.DDLStartM.SelectedItem.Value + ":00";
            string str4 = this.txtEndDate.Text.Trim() + " " + this.DDLEndH.SelectedItem.Value + ":" + this.DDLEndM.SelectedItem.Value + ":00";
            this.publicFun_0.ExecuteSql("delete from ZiSetInfo;insert into ZiSetInfo(JoinUserName,JoinUserCode,ExamStart,ExamEnd,ExamTime,JoinNum) values('," + str2 + ",','," + str + ",','" + str3 + "','" + str4 + "'," + this.txtTime.Text.Trim() + "," + this.txtNum.Text.Trim() + ")");
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckA", "alert('打字考试参数设置成功！')", true);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---设置打字参数";
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) == 0x3a)
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
                }
                else if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        this.ViewState["Power"] = this.publicFun_0.GetValues("select ZiManag from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ZiManag");
                        if (this.ViewState["Power"].ToString() == "N")
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BPower", "alert('打字参数设置权限未开放！')", true);
                            this.butDefault.Visible = false;
                        }
                        else
                        {
                            this.butDefault.Visible = true;
                        }
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select * from ZiSetInfo", connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.txtTime.Text = reader["ExamTime"].ToString();
                            this.txtStartDate.Text = Convert.ToDateTime(reader["ExamStart"]).ToShortDateString();
                            this.txtEndDate.Text = Convert.ToDateTime(reader["ExamEnd"]).ToShortDateString();
                            this.txtNum.Text = reader["JoinNum"].ToString();
                            this.DDLStartH.SelectedIndex = -1;
                            this.DDLStartM.SelectedIndex = -1;
                            this.DDLEndH.SelectedIndex = -1;
                            this.DDLEndM.SelectedIndex = -1;
                            this.DDLStartH.Items.FindByValue(Convert.ToDateTime(reader["ExamStart"]).Hour.ToString()).Selected = true;
                            this.DDLStartM.Items.FindByValue(reader["ExamStart"].ToString().Substring(reader["ExamStart"].ToString().IndexOf(":") + 1, 2)).Selected = true;
                            this.DDLEndH.Items.FindByValue(Convert.ToDateTime(reader["ExamEnd"]).Hour.ToString()).Selected = true;
                            this.DDLEndM.Items.FindByValue(reader["ExamEnd"].ToString().Substring(reader["ExamEnd"].ToString().IndexOf(":") + 1, 2)).Selected = true;
                            this.strReUserName = reader["JoinUserName"].ToString();
                            this.strReUserCode = reader["JoinUserCode"].ToString();
                            if (this.strReUserName.Length > 1)
                            {
                                this.strReUserName = this.strReUserName.Substring(1, this.strReUserName.Length - 2);
                                this.strReUserCode = this.strReUserCode.Substring(1, this.strReUserCode.Length - 2);
                            }
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        if (this.txtTime.Text.Trim() == "")
                        {
                            this.txtTime.Text = "5";
                            this.txtStartDate.Text = DateTime.Now.ToShortDateString();
                            this.txtEndDate.Text = DateTime.Now.AddDays(1.0).ToShortDateString();
                            this.txtNum.Text = "1";
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

